package org.jdesktop.swingx.table.model;

import javax.swing.table.TableModel;

public abstract class AbstractAddRowTableModelWapper<T extends TableModel> extends AbstractTableModelWapper<T> {

	protected int belowRowIndex;
	
	public AbstractAddRowTableModelWapper(T t,int belowRowIndex) {
		super(t);
		this.belowRowIndex=belowRowIndex;
	}

	public abstract Object getRowValue(int columnIndex);
	
	
	@Override
	public int getRowCount() {
		return super.getRowCount()+1;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if(rowIndex==belowRowIndex)
			return getRowValue(columnIndex);
		return super.getValueAt(rowIndex, columnIndex);
	}



	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		if(rowIndex==belowRowIndex)
			return false;
		return super.isCellEditable(rowIndex, columnIndex);
	}


	@Override
	public int getRealRowNumber(int wapperRowNum) {
		if(wapperRowNum==belowRowIndex)
			return -1;
		return super.getRealRowNumber(wapperRowNum);
	}

	@Override
	public int getRowIndex(int wapperRowIndex) {
		if(wapperRowIndex>belowRowIndex)
			wapperRowIndex--;
		return wapperRowIndex;
	}

	@Override
	public int getColumnIndex(int wapperColumnIndex) {
		return wapperColumnIndex;
	}
	
}
